import * as step from '@flow-step/step-toolkit'
import process from 'process'
import {getParams} from './params'
import {execute} from './execute'

export const IS_LINUX = process.platform === 'linux'
export const IS_X64 = process.arch === 'x64'

async function runStep(): Promise<void> {
    if (!IS_LINUX) {
        // outputs2template golang binary support linux only now
        throw new Error('SetupKubeConfig only supports Linux systems now')
    }

    const params = getParams()
    step.info(`PIPELINE_ID=${params.pipelineID}`)
    step.info(`PIPELINE_NAME=${params.pipelineName}`)
    step.info(`BUILD_NUMBER=${params.buildNumber}`)
    step.info(`WORK_SPACE=${params.workSpace}`)
    step.info(`PROJECT_DIR=${params.projectDir}`)
    step.info(`BUILD_JOB_ID=${params.buildJobID}`)
    step.info(`kubernetesCluster=${params.kubernetesCluster}`)
    step.info(`DEBUG=${params.debug}`)
    if(params.kubeConfigPath) {
        step.info(`kubeConfigPath=${params.kubeConfigPath}`)
    } else {
        step.info(`kubeConfigPath is not set, will use ~/.kube/config as default`)
    }

    await execute(params)
}

runStep()
    .then(function() {
        step.success('run step successfully!')
    })
    .catch(function(err: Error) {
        step.error(err.message)
        process.exit(-1)
    })
